package top.wineye.spring.ioc.container;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import top.wineye.model.User;

public class AnnotationApplicationContextAsContainer {


    public static void main(String[] args) {
        AnnotationConfigApplicationContext ac =
                new AnnotationConfigApplicationContext();
        ac.register(AnnotationApplicationContextAsContainer.class);
        // 要进行 refresh 否则报错 [contextObject] has not been refreshed yet
        ac.refresh();

        User user = ac.getBean(User.class);
        System.out.println("get bean by type from context: " + user);
    }

    @Bean
    public User user() {
        User u = new User();
        u.setId(2);
        u.setName("Jeff");
        return u;
    }


}
